#include <my_header.h>
#if 0
// 如下仅作为了解:
// 当线程被动取消， 通过pthread_join捕获的结束状态： PTHREAD_CANCELED ,本质值为-1
// 当线程主动退出：pthread_exit(PTHREAD_CANCELED)退出，pthread_join捕获的结束状态也是PTHREAD_CANCELED
#endif
/* Usage: ./11_pthread_cancel3 */
void * func(void *arg){
    while(1){
        sleep(1);
        printf("child thread printf \n");
    }
    return NULL;
}
int main()
{
    pthread_t  pid;
    int res = pthread_create(&pid, NULL, func, NULL);
    THREAD_ERROR_CHECK(res, "pthread_create");

    sleep(3);

    int res_cancel = pthread_cancel(pid);
    THREAD_ERROR_CHECK(res_cancel, "pthread_cancel");

    void *ret_catch ;
    int res_join = pthread_join(pid, &ret_catch);
    THREAD_ERROR_CHECK(res_join, "pthread_join");

    if(ret_catch == PTHREAD_CANCELED){
        printf("catch value = %ld \n", (long)ret_catch); // -1
    }else{
        printf("other value = %ld \n", (long)ret_catch);
    }

    return 0;
}

